﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Web.User;
using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_UserManager_EditDuty :PowerCreator.LMS.Web.Base.WebBasePage
{
    Duty opDuty = new Duty();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.UpdateDuty))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}

        if (!IsPostBack)
        {
            InitPage();

            string dutyid = Request.QueryString["DutyID"].ToString();
            ViewState["DutyID"] = dutyid;

            VOTTeacherDuty vo = opDuty.Load(int.Parse(dutyid));
            txt_Description.Text = vo.TeadutyDescription;
            txt_DutyName.Text = vo.TeadutyName;
        }
    }
    protected override void InitPage()
    {
        lbl_InfoTitle_EditDuty.Text = GetLanageValueByKey("lbl_EditDuty_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_EditDutyName.Text = GetLanageValueByKey("lbl_EditDuty_Name", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_EditDutyDescription.Text = GetLanageValueByKey("lbl_EditDuty_Description", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }
    private bool CheckPageData()
    {
        string search = string.Format(" TeadutyName = '{0}' and TeadutyID <> {1}", txt_DutyName.Text, ViewState["DutyID"]);
        if (opDuty.Count(search) != 0)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txt_Description.Text.Length > 200)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_max", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;

        VOTTeacherDuty vo = opDuty.Load(int.Parse(ViewState["DutyID"].ToString()));
        vo.TeadutyName = txt_DutyName.Text;
        vo.TeadutyDescription = txt_Description.Text;

        if (opDuty.Update(vo))
        {
            string url = "DutyManager.aspx";
            Script.RedirectURL(url);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "DutyManager.aspx";
        Script.RedirectURL(url);
    }
}
